package com.ruoyi.cfuser.rescue;

import com.ruoyi.cfuser.rescue.service.impl.InitiateRescueServiceImpl;
import com.ruoyi.common.redis.service.RedisService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.graphql.GraphQlProperties;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.geo.*;
import org.springframework.data.redis.connection.RedisGeoCommands;
import org.springframework.data.redis.core.GeoOperations;
import org.springframework.data.redis.core.RedisTemplate;

import javax.annotation.Resource;
import java.util.Map;

@SpringBootTest
public class testInit {

    @Resource
    private InitiateRescueServiceImpl initiateRescueService;
    @Qualifier("redisTemplate")
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private RedisService redisService;

    @Test
    public void testInit() {
        String citys = "citys";
        GeoOperations<String,String> geoOperations = redisTemplate.opsForGeo();
        geoOperations.add(citys,new Point(114,35),"1");
        geoOperations.add(citys,new Point(112,35),"2");
        geoOperations.add(citys,new Point(120,36),"3");
        geoOperations.add(citys,new Point(113,23),"4");
        geoOperations.add(citys,new Point(114,31),"5");
        geoOperations.add(citys,new Point(113,35.5),"6");
        geoOperations.add(citys,new Point(113.698,34.968),"7");

        Point center = new Point(113.617055,34.867994);
        Distance distance = new Distance(300, Metrics.KILOMETERS);
        Circle within = new Circle(center, distance);

        GeoResults<RedisGeoCommands.GeoLocation<String>> geoResults = geoOperations.radius(citys, within);
        for (GeoResult<RedisGeoCommands.GeoLocation<String>> geoResult : geoResults) {
            RedisGeoCommands.GeoLocation<String> content = geoResult.getContent();
            System.out.println(content.getName());
            System.out.println("======");

        }
    }

    @Test
    public void testInit2() {
        Map test = initiateRescueService.test("河南省郑州市金水区", "郑州");
        System.out.println("======="+test);
    }
}
